package cn.com.twoke.game.client.handler;

import cn.com.twoke.game.client.cache.ClientCacheManager;
import cn.com.twoke.game.client.ui.UiManager;
import cn.com.twoke.game.common.entity.message.LoginMessage;
import cn.com.twoke.game.common.handler.MessageHandler;

import java.io.IOException;
import java.nio.channels.Selector;
import java.nio.channels.SocketChannel;

public class LoginMessageHandler implements MessageHandler<LoginMessage> {

    @Override
    public void handle(Selector selector, SocketChannel channel, LoginMessage message) throws IOException {
        if (message.isState()) {
            ClientCacheManager.INSTANCE.setUsername(message.getUsername());
            UiManager.LOGIN.dispose();
            UiManager.WINDOW.open();
        } else { // 登录失败
            // UiManager.LOGIN.open();
            UiManager.LOGIN.showError(message.getMessage());
        }
    }

}
